package ibm.cognos.imt

/**
 * Created with IntelliJ IDEA.
 * User: eric
 * Date: 12/31/13
 * Time: 3:19 PM
 * To change this template use File | Settings | File Templates.
 */
class Query {
    def java.util.List dataItemList = new ArrayList()
    def name
    def java.util.List filterList = new ArrayList()
    def owner

    Query(report, name, elements) {

        this.name = name
        dataItemList = elements

//        dataItemList = element.dataItems()
    }

    def addFilter(filter) {
        filterList<<filter
        this
    }

    def generateSpec(xmlBuilder) {
        xmlBuilder.query(name: "$name") {
            source {
                model()
            }
            selection {
                dataItemList.each {
                    it.generateSpec(xmlBuilder)
                }
            }
            if (filterList.size() > 0) {
                detailFilters {
                    for (filter in filterList) {
//                        detailFilter(postAutoAggregation: "true", use: "required") {
//                            filterDefinition {
                                filter.generateSpec(xmlBuilder)
//                            }
//                        }
                    }
                }
            }
        }
    }
}
